//
//  PendingTableViewCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/21.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "PendingTableViewCell.h"

@interface PendingTableViewCell ()

@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * buyTypeLabel;
@property (nonatomic, weak)UILabel * volumeCountLabel;
@property (nonatomic, weak)UILabel * showVolumeCountLabel;
@property (nonatomic, weak)UILabel * buyMoneyCountLabel;
@property (nonatomic, weak)UILabel * buyMoneyLabel;
@property (nonatomic, weak)UILabel * nowMoneyCountLabel;
@property (nonatomic, weak)UILabel * nowMoneyLabel;
@property (nonatomic, weak)UIView * lineView;


@property (nonatomic, strong)NSArray * fiveArray;
@property (nonatomic, strong)NSArray * threeArray;
@property (nonatomic, strong)NSArray * twoArray;

@end

@implementation PendingTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    self.fiveArray = @[@"EURUSDapp",@"NZDUSDapp",@"EURCADapp",@"USDCADapp",@"EURNZDapp",@"AUDNZDapp",@"AUDUSDapp",@"AUDCADapp",@"GBPCHFapp",@"EURAUDapp",@"EURGBPapp",@"CADCHFapp",@"GBPAUDapp",@"EURCHFapp",@"USDCHFapp",@"GBPCADapp",@"GBPNZDapp",@"AUDCHFapp",@"GBPUSDapp"];
    self.threeArray = @[@"XAGUSDapp",@"GBPJPYapp",@"AUDJPYapp",@"USDJPYapp",@"EURJPYapp",@"CADJPYapp",@"NZDJPYapp"];
    self.twoArray = @[@"XAUUSDapp"];
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16 * SCREENH6];
    nameLabel.textColor = ColorWithRGB(0xffffff);
    nameLabel.textAlignment = NSTextAlignmentLeft;
//    nameLabel.text = @"USDCNH";
    
    self.nameLabel = nameLabel;
    
    [self addSubview:self.nameLabel];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.top.mas_equalTo(self).offset(8 * SCREENH6);
    }];
    
    
    UILabel * buyTypeLabel = [UILabel new];
    
    buyTypeLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16 * SCREENH6];
    buyTypeLabel.textAlignment = NSTextAlignmentLeft;
    buyTypeLabel.textColor = ColorWithRGB(0xc8c8c8);
//    buyTypeLabel.text = @"买涨挂单";
    
    self.buyTypeLabel = buyTypeLabel;
    
    [self addSubview:self.buyTypeLabel];
    
    [self.buyTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.nameLabel);
    }];
    
    
    UILabel * orderLabel = [UILabel new];
    
    orderLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16 * SCREENH6];
    orderLabel.textColor = ColorWithRGB(0xffffff);
    orderLabel.textAlignment = NSTextAlignmentLeft;
    orderLabel.hidden = YES;
    
    self.orderId = orderLabel;
    
    [self addSubview:self.orderId];
    
    [self.orderId mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.buyTypeLabel.mas_trailing);
        make.top.mas_equalTo(self.buyTypeLabel);
    }];

    
    
    UILabel * volumeCountLabel = [UILabel new];
    
    volumeCountLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    volumeCountLabel.textAlignment = NSTextAlignmentLeft;
    volumeCountLabel.textColor = ColorWithRGB(0x919395);
    volumeCountLabel.text = @"0.01";
    
    self.volumeCountLabel = volumeCountLabel;
    
    [self addSubview:self.volumeCountLabel];
    
    [self.volumeCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nameLabel);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    
    UILabel * showVolumeCountLabel = [UILabel new];
    
    showVolumeCountLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    showVolumeCountLabel.textColor = ColorWithRGB(0xfa6a6a6);
    showVolumeCountLabel.textAlignment = NSTextAlignmentLeft;
    showVolumeCountLabel.text = @"手数";
    
    self.showVolumeCountLabel = showVolumeCountLabel;
    
    [self addSubview:self.showVolumeCountLabel];
    
    [self.showVolumeCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.volumeCountLabel);
        make.top.mas_equalTo(self.volumeCountLabel.mas_bottom).offset(2 * SCREENH6);
    }];
    
    
    UILabel * buyMoneyCountLabel = [UILabel new];
    
    buyMoneyCountLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    buyMoneyCountLabel.textAlignment = NSTextAlignmentCenter;
    buyMoneyCountLabel.textColor = RED_COLOR;
    buyMoneyCountLabel.text = @"112.071";
    
    self.buyMoneyCountLabel = buyMoneyCountLabel;
    
    [self addSubview:self.buyMoneyCountLabel];
    
    [self.buyMoneyCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.volumeCountLabel);
    }];
    
    
    UILabel * buyMoneyLabel = [UILabel new];
    
    buyMoneyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    buyMoneyLabel.textColor = ColorWithRGB(0xfa6a6a6);
    buyMoneyLabel.textAlignment = NSTextAlignmentCenter;
    buyMoneyLabel.text = @"挂单价";
    
    self.buyMoneyLabel = buyMoneyLabel;
    
    [self addSubview:self.buyMoneyLabel];
    
    [self.buyMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.centerY.mas_equalTo(self.showVolumeCountLabel);
    }];
    
    
    UILabel * nowMoneyCountLabel = [UILabel new];
    
    nowMoneyCountLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    nowMoneyCountLabel.textAlignment = NSTextAlignmentRight;
    nowMoneyCountLabel.textColor = RED_COLOR;
    nowMoneyCountLabel.text = @"112.131";
    
    self.nowMoneyCountLabel = nowMoneyCountLabel;
    
    [self addSubview:self.nowMoneyCountLabel];
    
    [self.nowMoneyCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.buyMoneyCountLabel);
    }];
    
    UILabel * nowMoneyLabel = [UILabel new];
    
    nowMoneyLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    nowMoneyLabel.textAlignment = NSTextAlignmentRight;
    nowMoneyLabel.textColor = ColorWithRGB(0xfa6a6a6);
    nowMoneyLabel.text = @"现价";
    
    self.nowMoneyLabel = nowMoneyLabel;
    
    [self addSubview:self.nowMoneyLabel];
    
    [self.nowMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.nowMoneyCountLabel);
        make.centerY.mas_equalTo(self.buyMoneyLabel);
    }];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = [UIColor whiteColor];
    lineView.alpha = 0.1;
    
    self.lineView = lineView;
    
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
    
}


- (void)setModel:(PendingListModel *)model{
    
    _model = model;
    
    /*
     @property (nonatomic, weak)UILabel * nameLabel;
     @property (nonatomic, weak)UILabel * buyTypeLabel;
     @property (nonatomic, weak)UILabel * volumeCountLabel;
     @property (nonatomic, weak)UILabel * showVolumeCountLabel;
     @property (nonatomic, weak)UILabel * buyMoneyCountLabel;
     @property (nonatomic, weak)UILabel * buyMoneyLabel;
     @property (nonatomic, weak)UILabel * nowMoneyCountLabel;
     @property (nonatomic, weak)UILabel * nowMoneyLabel;
     */
    self.nameLabel.text = model.symbol;
    
    NSDictionary * dict = model.price;
    
    NSString * orderType = [NSString stringWithFormat:@"%@",model.orderType];
    NSString * orderDirection = [NSString stringWithFormat:@"%@",model.orderDirection];
    
    if ([orderType isEqualToString:@"Limit"]) {
//        self.buyTypeLabel.text = @"买涨挂单";
        self.buyMoneyCountLabel.textColor = RED_COLOR;
        self.nowMoneyCountLabel.textColor = RED_COLOR;
        
        self.nowMoneyCountLabel.text = dict[@"ask"];
    }else{
//        self.buyTypeLabel.text = @"买跌挂单";
        self.buyMoneyCountLabel.textColor = GREEN_COLOR;
        self.nowMoneyCountLabel.textColor = GREEN_COLOR;
        
        self.nowMoneyCountLabel.text = dict[@"bid"];
    }
    
    
    if ([orderDirection isEqualToString:@"Buy"] && [orderType isEqualToString:@"Limit"]) {
        
        self.buyTypeLabel.text = @"止盈买入";
    }else if ([orderDirection isEqualToString:@"Buy"] && [orderType isEqualToString:@"Stop"]){
        
       self.buyTypeLabel.text = @"止损买入";
    }else if ([orderDirection isEqualToString:@"Sell"] && [orderType isEqualToString:@"Limit"]){
        
        self.buyTypeLabel.text = @"止盈卖出";
    }else{
        
        self.buyTypeLabel.text = @"止损卖出";
    }
    
    BOOL isFivebool = [self.fiveArray containsObject:self.nameLabel.text];
    BOOL isThreebool = [self.threeArray containsObject:self.nameLabel.text];
    BOOL isTwobool = [self.twoArray containsObject:self.nameLabel.text];
    
    float openPrice = [model.orderPrice floatValue];
    
    if (isFivebool) {
        
        self.buyMoneyCountLabel.text = [NSString stringWithFormat:@"%.5f",openPrice];
    }
    
    if (isThreebool) {
        
        self.buyMoneyCountLabel.text = [NSString stringWithFormat:@"%.3f",openPrice];
    }
    
    if (isTwobool) {
        
        self.buyMoneyCountLabel.text = [NSString stringWithFormat:@"%.2f",openPrice];
    }
    
    self.volumeCountLabel.text = [NSString stringWithFormat:@"%@",model.volume];
//    self.buyMoneyCountLabel.text = [NSString stringWithFormat:@"%@",model.orderPrice];
    self.orderId.text = [NSString stringWithFormat:@"%@",model.orderId];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
